/* *
 *
 * @param {string} str
 * @returns {strings}
 */
const formatOutput = function (str) {
  let res = "";
  let j = 0;
  let suffix = str.split(".")[1];
  let arr = str.split(".")[0];
  for (let i = arr.length - 1; i > 0; i--) {
    res = arr[i] + res;
    j++;

    if (j == 3) {
      res = "," + res;
      j = 0;
    }
  }
  res = arr[0] + res;
  return suffix == undefined ? res : res + "." + suffix;
};

// 使用正则处理
const formatOutput = function (num) {
  return (num + "").replace(/(\d{1,3})((\d{3})+($|\.))/g, "$1,");
};

console.log(formatOutput("12345.123"));
